<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Data_poster extends CI_Model {

	function post_data($table,$post,$update=null)
	{
		if($update==null)
			$this->db->insert($table,$post);
		else
		{
			$this->db
				 ->where('intId',$update)
				 ->update($table,$post);
		}
	}
	
	function update_image($post,$update=null,$field = 'strFileName')
	{
		if($update!=null)
		{
			$this->db
				 ->where($field,$update)
				 ->update('tb_sys_media',$post);
			
			return 1;
		}
		return 0;
	}
		
	function delete_data($table,$id)
	{
		$this->db
			->where('intID',$id)
			->delete($table);
	}
	function add_vote_candidate_table($candidateID)
	{
		$this->db->select('intNewVoters');
		$candidate = current($this->db->get_where('tb_mas_candidates',Array('intID'=>$candidateID))->result_array());
		$votes = intval($candidate['intNewVoters']);
		$votes+=1;
		$data = array(
               'intNewVoters' => $votes
            );

		$this->db->where('intID', $candidateID);
		$this->db->update('tb_mas_candidates', $data);
	}
	
}
